@extends('layout.admin')
@section("content")

    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" style="padding-left: 0px;padding-right:0px;">
        <h1 class="page-header"><a href="/admin/realnews/create" type="button" class="btn btn-primary">新增</a></h1>
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th class="text-center">序号</th>
                    <th class="text-center">新闻标题</th>
                    <th class="text-center">创建时间</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php
                if ($newsList) {
                $i = ($newsList->currentPage() - 1) * $newsList->perPage() +1;
                foreach ($newsList as $news) {
                ?>
                <tr>
                    <td class="text-center"><?php echo $i;?></td>
                    <td class="text-center"><?php echo $news->title;?></td>
                    <td class="text-center"><?php echo date('Y-m-d H:i:s',$news->created);?></td>
                    <td class="text-center">
                        <a href="/admin/realnews/create?id=<?php echo isset($news['id'])?$news['id']:'';?>" type="button" class="btn btn-primary">编辑</a>
                        <button type="button" data-id="<?php echo isset($news['id'])?$news['id']:'';?>" class="btn btn-primary delete">删除</button>
                    </td>
                </tr>
                <?php
                $i++;
                }
                }
                ?>
                </tbody>
            </table>

            <input type="hidden" id = "_token" name="_token" value="<?php echo csrf_token(); ?>">
            <ul class="pagination pagination-lg">
                <?php echo $newsList->render();?>
            </ul>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            //删除
            $(".delete").click(function(){
                var id = $(this).attr('data-id');
                var _token = $("#_token").val();
                $.ajax({
                    url :'/admin/realnews/delete',
                    type:'POST',
                    data:'id='+id+'&_token='+_token,
                    dataType:'json',
                    success:function(data){
                        alert(data.msg);
                        window.location.reload();
                    }
                });
            });
        });
    </script>





@endsection